package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.nursing.dto.CheckInApplyDto;
import com.zzyl.nursing.vo.CheckInDetailVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.CheckIn;
import com.zzyl.nursing.service.ICheckInService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 入住Controller
 *
 * @author ruoyi
 * @date 2025-07-25
 */
@RestController
@RequestMapping("/nursing/checkIn" )
@Api(tags = "入住的接口" )
public class CheckInController extends BaseController {
    @Autowired
    private ICheckInService checkInService;

    /**
     * 申请入住
     * @param dto 前端传递的所有参数
     * @return  AjaxResult
     */
    @PostMapping("/apply" )
    public AjaxResult apply(@RequestBody CheckInApplyDto dto) {
        checkInService.apply(dto);
        return success();
    }

    /**
     * 查询入住列表
     */
    @ApiOperation("查询入住列表" )
    @PreAuthorize("@ss.hasPermi('nursing:checkIn:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(CheckIn checkIn) {
        startPage();
        List<CheckIn> list = checkInService.selectCheckInList(checkIn);
        return getDataTable(list);
    }

    /**
     * 导出入住列表
     */
    @ApiOperation("导出入住列表" )
    @PreAuthorize("@ss.hasPermi('nursing:checkIn:export')" )
    @Log(title = "入住", businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, CheckIn checkIn) {
        List<CheckIn> list = checkInService.selectCheckInList(checkIn);
        ExcelUtil<CheckIn> util = new ExcelUtil<CheckIn>(CheckIn.class);
        util.exportExcel(response, list, "入住数据" );
    }

    /**
     * 获取入住详细信息
     */
    @ApiOperation("获取入住详细信息" )
    @PreAuthorize("@ss.hasPermi('nursing:checkIn:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@ApiParam(value = "入住ID", required = true)
                              @PathVariable("id" ) Long id) {
        return success(checkInService.selectCheckInById(id));
    }

    /**
     * 新增入住
     */
    @ApiOperation("新增入住" )
    @PreAuthorize("@ss.hasPermi('nursing:checkIn:add')" )
    @Log(title = "入住", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(value = "入住实体" )
                          @RequestBody CheckIn checkIn) {
        return toAjax(checkInService.insertCheckIn(checkIn));
    }

    /**
     * 修改入住
     */
    @ApiOperation("修改入住" )
    @PreAuthorize("@ss.hasPermi('nursing:checkIn:edit')" )
    @Log(title = "入住", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(value = "入住实体" )
                           @RequestBody CheckIn checkIn) {
        return toAjax(checkInService.updateCheckIn(checkIn));
    }

    /**
     * 删除入住
     */
    @ApiOperation("删除入住" )
    @PreAuthorize("@ss.hasPermi('nursing:checkIn:remove')" )
    @Log(title = "入住", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(checkInService.deleteCheckInByIds(ids));
    }
/**
 * 查询入住详情
 */
@GetMapping("/detail/{id}")
@ApiOperation("查询入住详情")
public AjaxResult detail(@PathVariable("id") Long id){
    CheckInDetailVo checkInDetailVo = checkInService.detail(id);
    return success(checkInDetailVo);
}
}
